package day_2022_9_to_12.Day;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/10/13 17:50
 **/
public class Day41_3_Num228_SummaryRanges {
    class Solution {
        public List<String> summaryRanges(int[] nums) {
            List<String> res = new ArrayList<>();
            int i = 0, j = 0;
            while(i < nums.length){
                while(j < nums.length-1 && (nums[j] + 1) == nums[j+1]) j++;
                StringBuffer sb = new StringBuffer();
                if(i == j){
                    sb.append(nums[i]);
                    i++; j++;
                }else {
                    sb.append(nums[i]).append("->").append(nums[j]);
                    j++; i = j;
                }
                res.add(sb.toString());
            }
            return res;
        }
    }
}